package com.ylsk.check.domain.emum;

import com.google.common.collect.Maps;
import com.ylsk.common.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

public enum BasicInfoTemplateEnum {

    INS_ENTRY_REPORT("ins_entry_report", "进场上报","entryTime=%s,isJeeves=%s"),//进场时间  是否占道
    INS_JEEVES_REPORT("ins_jeeves_report", "占道上报","jeevesNum=%s,jeevesStartDate=%s,jeevesEndDate=%s,expresswayStartSectionName=%s,expresswayEndSectionName=%s"),//占道报备序号 占道开始日期 占道截止日期
    INS_WITHDRAWAL_REPORT("ins_withdrawal_report", "撤场上报","withdrawalTime=%s,endProject=%s"),//撤场时间 撤场类型
    INS_CHANGE_REPORT("ins_change_report", "变动上报","entryTime=%s,changeTime=%s");//进场时间 变动时间


    private static final Logger log = LoggerFactory.getLogger(BasicInfoTemplateEnum.class);

    public static Map<String,BasicInfoTemplateEnum> initMap  = Maps.newConcurrentMap();

    static {
        for (BasicInfoTemplateEnum value : BasicInfoTemplateEnum.values()) {
            initMap.put(value.getTbName(),value);
        }
    }


    public static Map<String,Object> getBasicInfo(String tbName,Object...parameters){
        if(StringUtils.isNotEmpty(tbName) && parameters != null && parameters.length >0 && null != initMap.get(tbName)){
            String format = String.format(initMap.get(tbName).getTemplate(), parameters);
            try {
                Map map = Arrays.stream(format.split(","))
                        .map(elem -> elem.split("="))
                        .collect(Collectors.toMap(e -> e[0], e -> e[1]));
                return map;
            }catch (Exception e ){
                log.error("构建基础信息失败 基础信息字符串内容= ",format);
                e.printStackTrace();
                return Maps.newConcurrentMap();
            }
        }
        return Maps.newConcurrentMap();
    }
    /**
     * 表名
     */
    private final String tbName;

    /**
     * 说明
     */
    private final String title;

    /**
     * 模板
     */
    private final String template;

    BasicInfoTemplateEnum(String tbName, String title, String template) {
        this.tbName = tbName;
        this.title = title;
        this.template = template;
    }

    public String getTbName() {
        return tbName;
    }

    public String getTitle() {
        return title;
    }

    public String getTemplate() {
        return template;
    }
}
